<extend name="Public:base" />
<block name="css">
    <link href="__CSS__/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="__CSS__/plugins/select2/select2.css" rel="stylesheet"/>
    <link href="__CSS__/plugins/waitMe/waitMe.min.css" rel="stylesheet">
    <link href="__CSS__/plugins/toastr/toastr.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="__CSS__/plugins/editormd/editormd.css" />
    <link rel="stylesheet" href="__CSS__/plugins/tagsinput/bootstrap-tagsinput.css" />
    <link rel="stylesheet" href="__CSS__/plugins/fileInput/fileinput.min.css" />
</block>
<block name="js">
    <script src="__JS__/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="__JS__/plugins/waitMe/waitMe.min.js"></script>
    <script src='__JS__/plugins/select2/select2.js'></script>
    <script src="__JS__/plugins/validForm/Validform_v5.3.2_min.js"></script>
    <script src="__JS__/plugins/toastr/toastr.min.js"></script>
    <script src="__JS__/plugins/editormd/editormd.min.js"></script>
    <script src="__JS__/plugins/tagsinput/bootstrap-tagsinput.js"></script>
    <script src="__JS__/plugins/fileInput/fileinput.min.js"></script>
    <script type='text/javascript'>
        $(function () {
            testEditor = editormd("test-editormd", {
                width: "100%",
                height: 740,
                //            syncScrolling: "single",
                path: "__JS__/plugins/editormd/lib/",
                previewCodeHighlight: true, // 关闭预览 HTML 的代码块高亮，默认开启
                emoji: true,
                name: 'post-content',
                toolbarAutoFixed: false,
                preview: false,
                taskList: true,
                tocm: true, // Using [TOCM]
                tex: true, // 开启科学公式TeX语言支持，默认关闭
                flowChart: true, // 开启流程图支持，默认关闭
                sequenceDiagram: true, // 开启时序/序列图支持，默认关闭,
                //dialogLockScreen : false,   // 设置弹出层对话框不锁屏，全局通用，默认为true
                //dialogShowMask : false,     // 设置弹出层对话框显示透明遮罩层，全局通用，默认为true
                //dialogDraggable : false,    // 设置弹出层对话框不可拖动，全局通用，默认为true
                //dialogMaskOpacity : 0.4,    // 设置透明遮罩层的透明度，全局通用，默认值为0.1
                //dialogMaskBgColor : "#000", // 设置透明遮罩层的背景颜色，全局通用，默认为#fff
                imageUpload: true,
                placeholder: "请输入文章内容",
                imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
                imageUploadURL: "./upload",
                saveHTMLToTextarea: true,
                onload: function () {
                    console.log('onload', this);
                    $('[name="watch"]').trigger('click');
                    //this.fullscreen();
                    //this.unwatch();
                    //this.watch().fullscreen();

                    //this.setMarkdown("#PHP");
                    //this.width("100%");
                    //this.height(480);
                    //this.resize("100%", 640);
                }

            });
            var search_url = "{:U('Tag/search')}";
            $("#search").click(function () {
                var params = $("#form").serialize();
                $("#refresh_box").waitMe(config.waitme);
                loadList(params);
            });

            $(".select-no-search").select2({
                theme: "classic",
                minimumResultsForSearch: -1
            });
            $(".select-search").select2({
                theme: "classic"
            });
            var validform = {beforeSubmit: function () {
                    $("textarea[name='post_content_html']").html(testEditor.getHTML());
                },
                ajaxPost: false
            };
            $("#form").Validform($.extend(config.validform, validform));
            var $special_img = $("input[name='special_img']");
            if ($special_img.attr('data-img-path')) {
                $("input[name='special_img']").fileinput({
                    initialPreview: [
                        "<img src='" + $special_img.attr('data-img-path') + "' class='file-preview-image'>",
                    ],
                    allowedFileExtensions: ["jpg", "gif", "png"],
                    browseIcon: '<i class="fa fa-folder-open"></i>',
                    showUpload: false,
                    showRemove: false,
                    browseLabel: '替换特色图片',
                    overwriteInitial: true
                });
            } else {
                $("#special_img").fileinput({
                    allowedFileExtensions: ["jpg", "gif", "png"],
                    browseIcon: '<i class="fa fa-folder-open"></i>',
                    showUpload: false,
                    showRemove: false,
                    browseLabel: '上传照片'
                });
            }
        });
    </script>
</block>
<block name="content">
    <form method="post" enctype="multipart/form-data" class="form-horizontal" <empty name='post_id'>action="{:U('Post/insert')}"<else/>action="{:U('Post/modify')}"</empty>  id="form">
        <div class="col-lg-9">
            <div class="ibox float-e-margins">
                <div class="form-group div-container">
                    <div><input type="text" class="form-control input-lg" name="post_title" id="post_title" value="{$post_title}"  placeholder="在此输入新文章标题"/></div>
                    <div class="Validform_checktip text-danger"></div>
                </div>
                <div class="form-group div-container">
                    <div id="test-editormd">
                        <textarea style="display:none;" name="post_content">{$post_content}</textarea>
                    </div>
                    <div class="Validform_checktip text-danger"></div>
                </div>            
                <!--</div>-->
            </div>
        </div>
        <div class="col-lg-3">
            <div> 
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>发布</h5>
                    </div>
                    <div class="ibox-content clearfix">
                        <div><button class="btn btn-white m-b" name='draft' type="submit">保存草稿</button><button class="btn btn-primary m-b pull-right" name='publish'  type="submit">发布</button></div>
                    </div>
                </div>
            </div>
            <div> 
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>形式</h5>
                    </div>
                    <div class="ibox-content clearfix">
                        <div id="post-formats-select" style="font-size:16px;">
                            <div class="radio"><label> <input type="radio" checked="" value="1"  name="type"><i class="fa fa-thumb-tack"></i>&nbsp;标准</label></div>
                            <div class="radio"><label> <input type="radio" value="2" <eq name="type" value="2">checked</eq>  name="type"><i class="fa fa-image"></i> 图像</label></div>
                            <div class="radio"><label> <input type="radio" value="3" <eq name="type" value="3">checked</eq> name="type"><i class="fa fa-video-camera"></i> 视频</label></div>
                            <div class="radio"><label> <input type="radio" value="4" <eq name="type" value="4">checked</eq> name="type"><i class="fa fa-music"></i> 音频</label></div>
                            <div class="radio"><label> <input type="radio" value="5" <eq name="type" value="5">checked</eq> name="type"><i class="fa fa-file-code-o"></i> 代码</label></div>
                            <div class="radio"><label> <input type="radio" value="6" <eq name="type" value="6">checked</eq> name="type"><i class="fa fa-quote-left"></i> 引语</label></div>
                            <div class="radio"><label> <input type="radio" value="7" <eq name="type" value="7">checked</eq> name="type"><i class="fa fa-book"></i> 日记</label></div>
                        </div>
                    </div>
                </div>
            </div>
            <div> 
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>分类</h5>
                    </div>
                    <div class="ibox-content clearfix" style="padding:0px;">
                        <div class="panel blank-panel">
                            <div class="panel-heading">
                                <div class="panel-options">
                                    <ul class="nav nav-tabs">
                                        <li class="active"><a data-toggle="tab" href="tabs_panels.html#tab-1" aria-expanded="true">分类</a></li>
                                        <li class=""><a data-toggle="tab" href="tabs_panels.html#tab-2" aria-expanded="false">新建分类</a></li>
                                    </ul>
                                </div>
                            </div>
                            <div class="panel-body">
                                <div class="tab-content">
                                    <div id="tab-1" class="tab-pane active">
                                        <volist name="itemList.list" id="vo">
                                            <div class="checkbox" style="text-indent:{$vo['level']*10}px"><label> <input type="checkbox" <if condition="in_array($vo['item_id'],$item_id_arr)">checked</if> value="{$vo.item_id}"  name="item_ids[]">{$vo.item_name}</label></div>
                                        </volist>
                                    </div>
                                    <div id="tab-2" class="tab-pane">
                                        <div class="add-new" data-toggle="add-new">
                                            <input type="text" name="item_name" class="form-control m-b m-t-sm" placeholder="分类名"/>
                                            <input type="text" name="alias" class="form-control m-b" placeholder="分类别名"/>
                                            <select name="pid" class="form-control m-b">
                                                <volist name="itemList.list" id="vo">
                                                    <option value="{$vo.item_id}">{$vo.item_name}</option>
                                                </volist>
                                            </select>
                                            <input type="button" class="btn btn-white" value="添加新分类目录"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div> 
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>标签</h5>
                    </div>
                    <div class="ibox-content clearfix">
                        <div class="bs-example">
                            <input type="text" value="{$tag_names}" data-role="tagsinput" name="tags" class='form-control' style="display: none;">
                        </div>
                    </div>
                </div>
            </div>
            <div> 
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>特色图片</h5>
                    </div>
                    <div class="ibox-content clearfix">
                        <input type="file" name="special_img" class="form-control" <notempty name="special_img_path">data-img-path="/data/{$special_img_path}"</notempty> id="special_img"/>
                    </div>
                </div>
            </div>
        </div>
        <textarea style="display: none;" name="post_content_html"></textarea>
    </form>
</block>
